<template>
  <!-- 历史付款记录修改-->
  <el-dialog
    :title="title"
    center
    :visible.sync="openState"
    v-if="openState"
    width="1024px"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <el-form ref="editForm" :model="editForm" :rules="editRules" label-width="110px">
      <el-card class="form-card payeeInfo-card">
        <div slot="header" class="label-header-msg">
          <span></span>
        </div>
        <el-row :gutter="10">
          <el-col :span="12">
            <div class="grid-payee">
              <el-form-item label="客户账号" prop="actNo">
                <acct-no-input
                  v-model="editForm.actNo"
                  placeholder="客户账号"
                  :disabled="true"
                />
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-form-item label="客户名称" prop="name">
          <el-input v-model="editForm.name" placeholder="客户名称"/>
        </el-form-item>
        <el-form-item label="客户地址" prop="addr">
          <el-input v-model="editForm.addr" placeholder="客户地址"/>
        </el-form-item>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payee">
              <el-form-item label="收款行行号" prop="rcvBrno">
                <BrnoInput
                  v-model="editForm.rcvBrno"
                  placeholder="收款行行号"
                  @keyup.enter.native="getBankInf('rcvBrno', editForm.rcvBrno)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="3">
            <div class="grid-payee">
              <el-button
                type="primary"
                icon="el-icon-search"
                plain
                @click="openBankBranchDialog('rcvBrno')"
              >
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="13">
            <el-form-item label="收款行行名" prop="rcvBrname" label-width="130px">
              <el-input v-model="editForm.rcvBrname" placeholder="收款行行名" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-payee">
              <el-form-item label="收款人开户行号" prop="accBrno">
                <BrnoInput
                  v-model="editForm.accBrno"
                  placeholder="收款人开户行行号"
                  @keyup.enter.native="getBankInf('accBrno', editForm.accBrno)"
                />
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="3">
            <div class="grid-payee">
              <el-button type="primary" icon="el-icon-search" plain @click="openBankBranchDialog('accBrno')">
                行号查找
              </el-button>
            </div>
          </el-col>
          <el-col :span="13">
            <el-form-item label="收款人开户行行名" prop="accBrnoName" label-width="130px">
              <el-input v-model="editForm.accBrnoName" placeholder="收款人开户行行名" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
    </el-form>
    <bank-branch-dialog ref="bankBranchDialog" @confirm="confirmBankBranch"></bank-branch-dialog>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">提 交</el-button>
      <el-button type="primary" @click="cancel">关 闭</el-button>
    </div>
  </el-dialog>
</template>
<script>
import BrnoSearchDialog from "@/views/components/BrnoSearchDialog";
import { listPageMixin } from "@/libs/listPageMixin";
import BankCodeSearchDialog from "@/views/components/BankCodeSearchDialog";
import BrnoInput from "@/views/components/BrnoInput";
import AcctNoInput from "@/views/components/AcctNoInput";
import { getBankInfByBankCode } from "@/api/cnaps/common/bankInfo";
import BankBranchDialog from "@/views/components/BankBranchDialog";
import { payinfoUpdate } from "@/api/cnaps/bizMng/payinfo";
export default {
  name: "payinfoEdit",
  mixins: [listPageMixin],
  components: {
    BankBranchDialog,
    AcctNoInput,
    BrnoInput,
    BankCodeSearchDialog,
    BrnoSearchDialog,
  },
  props: {

  },
  data() {
    return {
      title: "",
      // 是否显示弹出层
      openState: false,
      // 字段可编辑控制

      //数据字典
      searchFormDictList: [
        "ORGAN_SYSTYPE_BRANCH",
        "SYSTEMSTATUS",
        "ACCESS_POINT",
        "PT_TYPE",
      ],
      // 表单参数
      editForm: {
      },
      // 表单校验
      editRules: {
        actNo: [{ required: true, message: "请输入客户账号", trigger: "change" }],
        name: [{ required: true, message: "请输入客户名称", trigger: "change" }],
        rcvBrno: [{ required: true, message: "请输入收款行行号", trigger: "change" }],
        rcvBrname: [{ required: true, message: "请输入收款行行名", trigger: "change" }],
        accBrno: [{ required: true, message: "请输入收款人开户行号", trigger: "change" }],
        accBrnoName: [{ required: true, message: "请输入收款人开户行行名", trigger: "change" }],

      },
      opButtonList: () => {
        return [
        ];
      },
    };
  },
  mounted() {
  },
  methods: {
    // 表单重置
    reset() {
      this.resetForm("editForm");
      this.$set(this, "editForm", {});
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          this.reset();
          done();
        })
        .catch(_ => {});
    },
    show(row) {
      this.editForm = row;
      this.title = "历史付款记录维护修改";
      this.openState = true;
    },


    cancel() {
      this.openState = false;
      this.reset();
    },

    /** TODO提交按钮 */
    submitForm: function() {
      this.$refs["editForm"].validate(valid => {
        if (valid) {
          this.submit();
        }
      });
    },

    submit() {
      payinfoUpdate(this.editForm).then(res => {
        if (res.code === 'S') {
          this.msgSuccess("提交成功");
          this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
            confirmButtonText: "确定",
            //刷新一下查询列表
            callback: (action) => {
            },
          });
          this.$emit("editComplete", true);
          this.cancel();
        }
      });
    },

    bankCodeQry() {
      this.$refs.bankCodeSearchDialog.show();
    },

    //行名行号查询
    openBankBranchDialog(fromFlag = "") {
      this.$refs.bankBranchDialog.show(fromFlag);
    },


    //行名行号返回
    confirmBankBranch(fromFlag, row) {
      if (fromFlag === "rcvBrno") {
        this.$set(this.editForm, "rcvBrno", row.bankCode);
        this.$set(this.editForm, "rcvBrname", row.orgFullname);
      } else if (fromFlag === "accBrno") {
        this.$set(this.editForm, "accBrno", row.bankCode);
        this.$set(this.editForm, "accBrnoName", row.orgFullname);
      }
    },

    //回车取行号信息
    getBankInf(searchType, bankCode) {
      getBankInfByBankCode(bankCode).then((response) => {
        if (response.code == "S" && response.result !== undefined) {
          switch (searchType) {
            case "rcvBrno":
              this.$set(this.editForm, "rcvBrno", response.result.bankCode);
              this.$set(this.editForm, "rcvBrname", response.result.orgFullname);
              break;
            case "accBrno":
              this.$set(this.editForm, "accBrno", response.result.bankCode);
              this.$set(this.editForm, "accBrnoName", response.result.orgFullname);
              break;
          }
        } else {
          this.msgSuccess("查无此行号");
          switch (searchType) {
            case "rcvBrno":
              this.$set(this.editForm, "rcvBrname", null);
              break;
            case "accBrno":
              this.$set(this.editForm, "accBrnoName", null);
              break;
          }
        }
      });
    },

  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
